/*
 * Copyright (C) 2017-2021
 * All rights reserved, Designed By 深圳中科鑫智科技有限公司
 * Copyright authorization contact 18814114118
 */
package com.shop.cereshop.app.controller.group;

import com.shop.cereshop.app.annotation.NoRepeatSubmit;
import com.shop.cereshop.app.annotation.NoRepeatWebLog;
import com.shop.cereshop.app.service.group.CereShopGroupService;
import com.shop.cereshop.commons.constant.CoReturnFormat;
import com.shop.cereshop.commons.domain.shop.CereShopGroup;
import com.shop.cereshop.commons.domain.shop.bo.CereShopGroupBo;
import com.shop.cereshop.commons.domain.shop.vo.CereShopGroupVo;
import com.shop.cereshop.commons.exception.CoBusinessException;
import com.shop.cereshop.commons.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * 店铺商品分组
 */
@RestController
@RequestMapping("/group")
/**
 * 注解方式生成日志对象，指定topic生成对象类名
 */
@Slf4j(topic = "ShopGroupController")
@Api(value = "店铺商品分组模块", tags = "店铺商品分组模块")
public class ShopGroupController {

    @Autowired
    private CereShopGroupService cereShopGroupService;

    /**
     * 查询分组
     */
    @GetMapping(value = "/queryList")
    @NoRepeatSubmit
    @ApiOperation(value = "查询分组")
    @NoRepeatWebLog
    public Result queryList(CereShopGroupBo bo) throws CoBusinessException{
        List<CereShopGroupVo> voList = cereShopGroupService.queryList(bo);
        Collections.reverse(voList);
        for (CereShopGroupVo vo : voList) {
            CereShopGroupBo param = new CereShopGroupBo();
            param.setSuperGroupId(vo.getShopGroupId());
            List<CereShopGroupVo> child = cereShopGroupService.queryList(param);
            vo.setShopGroupChildVos(child);
            Collections.reverse(child);
        }
        return new Result(voList, CoReturnFormat.SUCCESS);
    }

}
